<?php
namespace app\admin\controller;

use app\BaseController;
use think\facade\View;
use think\facade\Request;
use think\facade\Db;
use think\facade\Session;

class Index extends BaseController
{
    protected $middleware = [
        \app\admin\middleware\Check::class => ['except' =>['login']]
    ];

    public function initialize() {

        $controller_action_name = '/'.Request::controller(true).'/'.Request::action();

        $menus = [
            "/admin/index/adminManager"=>"管理员管理",
            "/admin/index/goodsManager"=>"物品管理",
            "/admin/index/cateManager"=>"分类管理",
            "/admin/index/spaceManager"=>"空间管理",
            "/admin/index/imageManager"=>"图片管理",
        ];
        $userinfo = Session::get('userinfo');
        View::assign([
            'menus' => $menus,
            'controller_action_name' => $controller_action_name,
            'userinfo' => $userinfo
        ]);
    }

    public function index(\think\Request $request)
    {
        $userinfo = $request->userinfo;
        
        return View::fetch('usercenter',["userinfo" => $userinfo]);
    }

    /**
     * 管理员管理
     * 
     * 
     */
    public function adminManager()
    {
        //$groupList = Db::table('gms_system_auth')->where('id','<>',1)->select();
        $groupList = Db::table('gms_system_auth')->select();
        return View('',[
            "groupList"=>$groupList,
            "title"=>"管理员"
        ]);
    }

        /**
     * 物品管理
     * 
     * 
     */
    public function goodsManager()
    {
        $goodsList = Db::table('gms_good_goods')->select();
        $cateList = Db::table('gms_good_cate')->select();
        $db = new \app\admin\model\GoodSpace;
        $datas = $db->getTreeData();
        $spaceList =  buildOptions($datas); 
        return View('',[
            "groupList"=>$goodsList,
            "cateList" => $cateList,
            "spaceList" => $spaceList,
            "title"=>"物品管理"
        ]);
    }

    /**
     * 物品分类管理
     * 
     * 
     */
    public function cateManager()
    {
        return View('',[
            "title"=>"物品分类管理"
        ]);
    }

        /**
     * 权限管理
     * 
     * 
     */
    public function nodeManager()
    {
        return View('',[
            "title"=>"权限"
        ]);
    }
    /**
     * 物品分类管理
     * 
     * 
     */
    public function spaceManager()
    {
               
        $spaceList = Db::name('good_space')->select();
        return View('',[
            "spaceList" => $spaceList,
            "title"=>"物品空间管理"
        ]);
    }

    public function imageManager()
    {
        $imageList = \app\admin\model\SystemUploadfile::select();
        return View('',[
            "imageList" => $imageList,
            "title"=>"图片管理"
        ]);
    }
    /**
     * 用户登录
     * 
     * @return View
     */
    public function login()
    {
        //var_dump(Session::get("userinfo"));
        $redirect_url = request()->get('redirect_url','./index');
        return View::fetch('',[
            "redirect_url" => $redirect_url
        ]);
    }

    /**
     * 用户登录
     * 
     * @return View
     */
    public function logout()
    {
        //var_dump(Session::get("userinfo"));
        $redirect_url = request()->get('redirect_url','./index');
        return redirect($redirect_url);
    }    
}